package com.jspx.txweb.view;

import com.jspx.txweb.annotation.HttpMethod;
import com.jspx.txweb.annotation.Safety;
import com.jspx.txweb.dao.DFAFilter;
import com.jspx.txweb.support.ActionSupport;
import java.util.Set;

/**
 * Created by yuan on 2015/6/16 0016.
 *
 */
@HttpMethod(caption = "屏蔽关键词")
public class WordFilterView extends ActionSupport {
    ///////////////载入IOC DAO 对象 begin
    protected DFAFilter filter;
    public void setFilter(DFAFilter filter) {
        this.filter = filter;
    }
    ///////////////载入IOC DAO 对象 end
    public  int matchType = 1;      //最小匹配规则
    @Safety
    public void setMatchType(int matchType) {
        if (matchType==1||matchType==2) this.matchType = matchType;
    }

    private String caption;
    public String getCaption() {
        return caption;
    }

    public void setCaption(String caption) {
        this.caption = caption;
    }

    private String text;
    @Safety(empty=false,length = 10000)
    public void setText(String text) {
        this.text = text;
    }

    public Set<String> getSearch() throws Exception {
        Set<String> result = filter.search(text,matchType);
        if (!result.isEmpty()) filter.updateTimes(result);
        return filter.getOriginal(result);
    }

    public String replace() throws Exception {
        return filter.replace(text,matchType,"*");
    }


}
